package tt.dz.egobus.servicemanager.business.point;

/**
 * @author Anson
 * @date 17-3-23
 * @name 坐标相关算法集成
 * @since 1.0.2
 */
public final class PointAlgorithmHelp {

    /**
     * @param point
     * @param x
     * @param y
     * @author Anson
     * @date 17-3-24
     * @name 计算坐标距离非实际距离
     * @since 1.0.2
     */
    public static final double accPointLength(Point point, double x, double y) {
        double bx = point.x();
        double by = point.y();
        return accPointLength(bx, by, x, y);
    }

    /**
     * @param x1
     * @param y1
     * @param x2
     * @param y2
     * @author Anson
     * @date 17-3-24
     * @name 计算坐标距离非实际距离
     * @since 1.0.2
     */
    public static final double accPointLength(double x1, double y1, double x2, double y2) {
        return Math.sqrt(Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2));
    }

    /**
     * @param start
     * @param end
     * @author Anson
     * @date 17-3-24
     * @name 计算两点之间距离（距离为M米)
     * @since 1.0.2
     */
    public static double getDistance(Point start, Point end) {
        return accDistanceByPoint(start.x(), start.y(), end.x(), end.y());
    }

    /**
     * @param x1
     * @param y1
     * @param x2
     * @param y2
     * @author Anson
     * @date 17-3-24
     * @name 计算两点之间距离（距离为M米)
     * @since 1.0.2
     */
    public static final double accDistanceByPoint(double x1, double y1, double x2, double y2) {
        double lon1 = (Math.PI / 180) * x1;
        double lon2 = (Math.PI / 180) * x2;
        double lat1 = (Math.PI / 180) * y1;
        double lat2 = (Math.PI / 180) * y2;
        // 地球半径
        double R = 6371;
        // 两点间距离 km，如果想要米的话，结果*1000就可以了
        double d = Math.acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1))
                * R;
        return d * 1000;
    }

}
